package L7.L710;

/**
 * 两个正整数a和b（a>b），它们的最大公约数等于a除 以b的余数c和b之间的最大公约数
 *
 * @author: luolidong
 * @create: 2021-07-10 15:04
 * @version: 1.0
 */
public class Demo {
    /**
    * @Description: 欧几里得算法，辗转相除
    * @Param: [a, b]
    * @return: int
    */
    public int getGreatestCommonDivisor(int a, int b) {
        int max = Math.max(a, b);
        int min = Math.min(a, b);
        if (max%min==0){
            return min;
        }
        return getGreatestCommonDivisor(max%min, min);
    }
    /**
    * @Description: 更相减损术
    * @Param: [a, b]
    * @return: int
    */
    public int getGreatestCommonDivisor1(int a, int b) {
        if(a==b) return a;
        int max = Math.max(a, b);
        int min = Math.min(a, b);
        return getGreatestCommonDivisor1(max-min, min);
    }
    public int m(int a,int b){
        if(b==0){
            return a;
        }else {
            return m(b,a%b);
        }
    }
    /**
    * @Description: 最小公倍数=两数相乘/最大公约数
    * @Param: [a, b]
    * @return: int
    */
    public int getMinCommonMultiple(int a,int b){
        return (a*b)/getGreatestCommonDivisor(a,b);
    }

    public static void main(String[] args) {
        Demo demo = new Demo();
        int greatestCommonDivisor = demo.getGreatestCommonDivisor(220, 48);
        System.out.println("greatestCommonDivisor = " + greatestCommonDivisor);

        int greatestCommonDivisor2 = demo.getGreatestCommonDivisor1(220, 48);
        System.out.println("greatestCommonDivisor2 = " + greatestCommonDivisor2);

        int minCommonMultiple = demo.getMinCommonMultiple(24, 48);
        System.out.println("minCommonMultiple = " + minCommonMultiple);

        int m = demo.m( 4,6);
        System.out.println(m);

    }
}
